/**
 * 
 */
package com.nh.action;

import java.sql.Timestamp;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.nh.entity.NgInteractiveRecovery;
import com.nh.entity.NgInteractiveTopic;

/**
 * 项目名称：NotoginsengManage
 * 
 * 类名称：InteractiveAction
 * 
 * 类描述：
 * 
 * 创建人：李兴建
 * 
 * E-mail:lxj08193@163.com
 * 
 * 创建时间：2012-11-8 下午07:29:52
 * 
 * 修改人：李兴建
 * 
 * 修改时间：2012-11-8 下午07:29:52
 * 
 * 修改备注：
 * 
 * @version
 */
public class InteractiveAction extends BaseAction {

	private Long optionId;
	private Long recoveryId;
	private NgInteractiveTopic interactiveTopic;
	private NgInteractiveRecovery interactiveRecovery;

	/**
	 * 话题列表
	 * 
	 * @return
	 */
	public String interactiveList() {
		Criteria criteria = this.createCriteria(NgInteractiveTopic.class);
		criteria.add(Restrictions.lt("verification", 2));
		criteria.addOrder(Order.desc("orderView"));
		criteria.addOrder(Order.desc("publishTime"));
		this.queryByPage(criteria, "interactiveAction!interactiveList.action", 10);

		this.setTitle("话题管理列表");
		return "interactiveList";
	}

	/**
	 * 等待审核
	 * 
	 * @return
	 */
	public String waitVerification() {
		Criteria criteria = this.createCriteria(NgInteractiveTopic.class);
		criteria.add(Restrictions.eq("verification", 0));
		criteria.addOrder(Order.desc("createTime"));
		this.queryByPage(criteria, "interactiveAction!interactiveList.action", 10);
		this.setTitle("等待审核列表");
		return "interactiveList";
	}

	/**
	 * 通过审核列表
	 * 
	 * @return
	 */
	public String verificationThroughList() {
		Criteria criteria = this.createCriteria(NgInteractiveTopic.class);
		criteria.add(Restrictions.eq("verification", 1));
		criteria.addOrder(Order.desc("verificationTime"));
		criteria.addOrder(Order.desc("orderView"));
		this.queryByPage(criteria, "interactiveAction!interactiveList.action", 10);
		this.setTitle("通过审核列表");
		return "interactiveList";
	}

	/**
	 * 删除列表
	 * 
	 * @return
	 */
	public String verificationDelete() {
		Criteria criteria = this.createCriteria(NgInteractiveTopic.class);
		criteria.add(Restrictions.eq("verification", 2));
		this.queryByPage(criteria, "interactiveAction!verificationDelete.action", 10);
		this.setTitle("已删除列表");
		return "interactiveList";
	}

	/**
	 * 通过审核
	 * 
	 * @return
	 */
	public String verificationThrough() {
		NgInteractiveTopic interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		interactiveTopic.setVerification(1);
		interactiveTopic.setPublishTime(new Timestamp(System.currentTimeMillis()));
		interactiveTopic.setVerificationAdminString("test");
		interactiveTopic.setVerificationTime(new Timestamp(System.currentTimeMillis()));
		this.getBaseService().saveOrUpdate(interactiveTopic, NgInteractiveTopic.class);
		return interactiveList();
	}

	/**
	 * 取消通过
	 */
	public String verificationReThrough() {
		NgInteractiveTopic interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		interactiveTopic.setVerification(2);
		interactiveTopic.setVerificationReAdmin("test");
		interactiveTopic.setVerificationReTime(new Timestamp(System.currentTimeMillis()));

		this.getBaseService().saveOrUpdate(interactiveTopic, NgInteractiveTopic.class);
		return interactiveList();
	}

	/**
	 * 删除
	 * 
	 * @return
	 */
	public String interactiveRemove() {
		NgInteractiveTopic interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		interactiveTopic.setVerification(2);
		this.getBaseService().saveOrUpdate(interactiveTopic, NgInteractiveTopic.class);
		return interactiveList();

	}

	/**
	 * 置顶
	 * 
	 * @return
	 */
	public String interactiveToTop() {
		NgInteractiveTopic interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		interactiveTopic.setTop(1);
		interactiveTopic.setPublishTime(new Timestamp(System.currentTimeMillis()));
		this.getBaseService().saveOrUpdate(interactiveTopic, NgInteractiveTopic.class);
		return verificationThroughList();
	}

	/**
	 * 发布话题页面
	 * 
	 * @return
	 */
	public String interactiveAddPage() {
		interactiveTopic = new NgInteractiveTopic();
		interactiveTopic.setTop(0);
		interactiveTopic.setOrderView(0);
		interactiveTopic.setVerification(0);
		this.setTitle("发布话题");
		return "interactiveAddPage";
	}

	/**
	 * 修改页面
	 * 
	 * @return
	 */
	public String interactiveModify() {
		interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		this.setTitle("修改话题");
		return "interactiveAddPage";
	}

	/**
	 * 保存
	 * 
	 * @return
	 */
	public String interactiveSave() {
		interactiveTopic.setCreateTime(new Timestamp(System.currentTimeMillis()));
		if (interactiveTopic.getVerification() == 1) {
			interactiveTopic.setPublishTime(new Timestamp(System.currentTimeMillis()));
		}
		if (null != interactiveTopic.getId()) {
			this.getBaseService().saveOrUpdate(interactiveTopic, NgInteractiveTopic.class);
		} else {
			interactiveTopic.setAdmintag(1);
			interactiveTopic.setUserCode(this.getCurrentAdmin().getId());
			interactiveTopic.setRevoverCount(0);
			interactiveTopic.setVisitViewCount(0);
			this.getBaseService().save(interactiveTopic);
		}

		return interactiveList();
	}

	/**
	 * 回复
	 * 
	 * @return
	 */
	public String recoveryAdd() {
		interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		interactiveRecovery = new NgInteractiveRecovery();
		this.setTitle("回复");
		return "recovery";
	}

	/**
	 * 保存服务
	 * 
	 * @return
	 */
	public String recoverySave() {
		interactiveRecovery.setRecoverTime(new Timestamp(System.currentTimeMillis()));
		interactiveRecovery.setRecoveryType(1);
		interactiveRecovery.setUserStr("test");
		interactiveRecovery.setRecoveryId(interactiveTopic.getId());
		this.getBaseService().save(interactiveRecovery);

		interactiveTopic = this.getBaseService().findById(interactiveTopic.getId(), NgInteractiveTopic.class);
		interactiveTopic.setRevoverCount(interactiveTopic.getRevoverCount() + 1);
		this.getBaseService().saveOrUpdate(interactiveRecovery, NgInteractiveTopic.class);
		return verificationThroughList();
	}

	/**
	 * 回复列表
	 * 
	 * @return
	 */
	public String interactiveRecoveryList() {
		interactiveTopic = this.getBaseService().findById(optionId, NgInteractiveTopic.class);
		Criteria criteria = this.createCriteria(NgInteractiveRecovery.class);
		criteria.addOrder(Order.desc("recoverTime"));
		criteria.add(Restrictions.eq("recoveryId", interactiveTopic.getId()));
		this.queryByPage(criteria, "interactiveAction!interactiveRecoveryList.action", 10);
		this.setTitle("回复列表");
		return "interactiveRecoveryList";
	}

	/**
	 * 删除回复
	 * 
	 * @return
	 */
	public String recoveryRemove() {
		this.getBaseService().delete(recoveryId, NgInteractiveRecovery.class);
		return interactiveRecoveryList();
	}

	/**
	 * @return the interactiveTopic
	 */
	public NgInteractiveTopic getInteractiveTopic() {
		return interactiveTopic;
	}

	/**
	 * @param interactiveTopic
	 *            the interactiveTopic to set
	 */
	public void setInteractiveTopic(NgInteractiveTopic interactiveTopic) {
		this.interactiveTopic = interactiveTopic;
	}

	/**
	 * @return the optionId
	 */
	public Long getOptionId() {
		return optionId;
	}

	/**
	 * @param optionId
	 *            the optionId to set
	 */
	public void setOptionId(Long optionId) {
		this.optionId = optionId;
	}

	/**
	 * @return the interactiveRecovery
	 */
	public NgInteractiveRecovery getInteractiveRecovery() {
		return interactiveRecovery;
	}

	/**
	 * @param interactiveRecovery
	 *            the interactiveRecovery to set
	 */
	public void setInteractiveRecovery(NgInteractiveRecovery interactiveRecovery) {
		this.interactiveRecovery = interactiveRecovery;
	}

	/**
	 * @return the recoveryId
	 */
	public Long getRecoveryId() {
		return recoveryId;
	}

	/**
	 * @param recoveryId
	 *            the recoveryId to set
	 */
	public void setRecoveryId(Long recoveryId) {
		this.recoveryId = recoveryId;
	}

}
